package com.example.learn.controller;

import com.example.learn.entity.DebtStatistics;
import com.example.learn.entity.MemorandumForm;
import com.example.learn.entity.User;
import com.example.learn.service.DebtstatisticalService;
import com.example.learn.service.MemorandumFormService;
import com.example.learn.token.CurrentUser;
import com.example.learn.token.UserLoginToken;
import com.example.learn.utile.Response.BaseResponse;
import com.example.learn.utile.Response.ObjectRestResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;


import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/api/memorandumform")
public class MemorandumFormController {
    @Autowired
    MemorandumFormService memorandumFormService;

    @UserLoginToken
    @RequestMapping(value = "getmemorandum",method = RequestMethod.GET)
    public BaseResponse getmemorandum(String name, @DateTimeFormat(pattern = "yyyy-MM-dd")Date startdate,@DateTimeFormat(pattern = "yyyy-MM-dd") Date enddate, String isfinish){
        MemorandumForm  memorandumForm =new MemorandumForm();
        memorandumForm.setName(name);
        memorandumForm.setStartdate(startdate);
            memorandumForm.setEnddate(enddate);
            String temfilish;
            if(isfinish=="未完成"){
                temfilish="0";
            memorandumForm.setIsfinish(temfilish);
        }else if(isfinish=="已完成"){
            temfilish="1";
            memorandumForm.setIsfinish(temfilish);
        }else{
          memorandumForm.setIsfinish("");
        }


        List<MemorandumForm> incomeList=      memorandumFormService.getmemorandum(memorandumForm);
        return new ObjectRestResponse().data(incomeList);
    }

    @UserLoginToken
    @RequestMapping(value = "adddmemorandum",method = RequestMethod.POST)
    public BaseResponse addDebtstatistical(@RequestBody MemorandumForm memorandumForm , @CurrentUser User user){
        String adddmemorandumStr=      memorandumFormService.adddmemorandum(memorandumForm,user);
        return new ObjectRestResponse().data(adddmemorandumStr);
    }

//    @RequestMapping(value = "deletememorandum",method = RequestMethod.POST)
//    public BaseResponse deleteDebtstatistical(String id){
//        String incomeStr=      debtstatisticalService.deleteDebtstatistical(id);
//        return new ObjectRestResponse().data(incomeStr);
//    }

    @UserLoginToken
    @RequestMapping(value = "updatememorandum",method = RequestMethod.POST)
    public BaseResponse updatememorandum(@RequestParam String isfinish ,@RequestParam String id,@CurrentUser User user){
        String adddmemorandumStr=      memorandumFormService.updatememorandum(isfinish,id,user);

        return new ObjectRestResponse().data(adddmemorandumStr);
    }

}
